package com.kpx.app.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.kpx.app.R;
import com.kpx.app.base.ActivityBase;
import com.kpx.app.bean.OrderBean;
import com.kpx.app.bean.RequirementMapBean;
import com.kpx.app.bean.TaskBean;
import com.kpx.app.configs.Constants;
import com.kpx.app.utils.TimeUtil;
import com.kpx.app.utils.UIUtils;
import com.kpx.app.utils.uiutils.IntentUtil;

import java.text.DecimalFormat;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/6/8.
 */

public class ActivityThirdOrderDo extends ActivityBase {

    @BindView(R.id.img_task)
    ImageView imgTask;
    @BindView(R.id.txt_pro_name)
    TextView txtProName;
    @BindView(R.id.txt_sex)
    TextView txtSex;
    @BindView(R.id.txt_age)
    TextView txtAge;
    @BindView(R.id.txt_height)
    TextView txtHeight;
    @BindView(R.id.txt_weight)
    TextView txtWeight;
    @BindView(R.id.txt_danbao_price)
    TextView txtDanbaoPrice;
    @BindView(R.id.txt_yongjin_price)
    TextView txtYongjinPrice;
    @BindView(R.id.txt_request1)
    TextView txtRequest1;
    @BindView(R.id.txt_request)
    TextView txtRequest;
    @BindView(R.id.txt_request3)
    TextView txtRequest3;
    @BindView(R.id.btn_suborder)
    Button btnSuborder;
    @BindView(R.id.btn_suborder2)
    Button btnSuborder2;
    @BindView(R.id.img_show)
    ImageView img_show;
    @BindView(R.id.txt_shop)
    TextView txtShop;
    @BindView(R.id.ll_shop)
    LinearLayout llShop;
    @BindView(R.id.txt_app_mention)
    TextView txtAppMention;
    @BindView(R.id.txt_acount)
    TextView txtAcount;
    @BindView(R.id.ll_acount)
    LinearLayout llAcount;
    @BindView(R.id.txt_order_time)
    TextView txtOrderTime;
    @BindView(R.id.ll_time)
    LinearLayout llTime;
    @BindView(R.id.ll_flow_show)
    LinearLayout llFlowShow;
    @BindView(R.id.txt_star)
    TextView txtStar;
    @BindView(R.id.txt_shose_size)
    TextView txtShoseSize;
    @BindView(R.id.txt_yj)
    TextView txtYj;
    private OrderBean b;
    private TaskBean taskBean;

    @Override
    public void initview(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_third_order_do);
        ButterKnife.bind(this);
        setTitleStr("试客任务");
    }

    @Override
    public void initData() {
        b = (OrderBean) getIntent().getExtras().getSerializable(Constants.KEY_ORDER_BEAN);
        if (b != null) {
            if (!UIUtils.isEmpty(b.getSellerName())) {
                llShop.setVisibility(View.VISIBLE);
                txtShop.setText(b.getSellerName());
                llFlowShow.setVisibility(View.VISIBLE);
                txtRequest3.setText(b.getPostageString());
                txtRequest1.setText(b.getBrushRequirement());
                if (!TextUtils.isEmpty(b.getBrushWorkflowPic())) {
                    Glide.with(ActivityThirdOrderDo.this).load(b.getBrushWorkflowPic()).into(img_show);
                }
                if (!UIUtils.isEmpty(b.getSellerName())) {
                    llShop.setVisibility(View.VISIBLE);
                    txtShop.setText("\"" + b.getSellerName() + "\"");
                }
                if (!UIUtils.isEmpty(b.getThirdAccount())) {
                    txtAcount.setText("\"" + b.getThirdAccount() + "\"");
                }
                txtOrderTime.setText(TimeUtil.getFormatTime(b.getFinishedTime(), TimeUtil.FORMAT_TIME_MINUTES_TWO));
            }
        }
        taskBean = (TaskBean) getIntent().getExtras().getSerializable(Constants.KEY_TASK_BEAN);
        if (taskBean != null) {
            Glide.with(this).load(taskBean.getTaskGoods().getMainPic()).into(imgTask);
            txtProName.setText(taskBean.getTaskGoods().getGoodsName());
            txtAge.setText("年龄：" + (taskBean.getRequirementMap() == null || UIUtils.isEmptyTask(taskBean.getRequirementMap().getAge()) ? "不限" : (taskBean.getRequirementMap().getAge() + "")));
            txtHeight.setText("身高：" + (taskBean.getRequirementMap() == null || UIUtils.isEmptyTask(taskBean.getRequirementMap().getHeight()) ? "不限" : taskBean.getRequirementMap().getHeight() + ""));
            txtSex.setText("性别：" + getSex(taskBean.getRequirementMap()));
            txtWeight.setText("体重：" + (taskBean.getRequirementMap() == null || UIUtils.isEmptyTask(taskBean.getRequirementMap().getWeight()) ? "不限" : taskBean.getRequirementMap().getWeight() + ""));
            txtStar.setText("等级：" + (taskBean.getRequirementMap() == null || UIUtils.isEmptyTask(taskBean.getRequirementMap().getLevel()) ? "不限" : taskBean.getRequirementMap().getLevel() + ""));
            txtShoseSize.setText("鞋码：" + (taskBean.getRequirementMap() == null || UIUtils.isEmptyTask(taskBean.getRequirementMap().getSize()) ? "不限" : taskBean.getRequirementMap().getSize() + ""));

            txtRequest1.setText(taskBean.getRequirementTxt());
            txtDanbaoPrice.setText(df.format(taskBean.getDeposit()));
            txtYongjinPrice.setText(taskBean.getTaskType() == 1 ? df.format(taskBean.getCommission()) : "赠送实物");
            findViewById(R.id.txt_yj).setVisibility(taskBean.getTaskType() == 1 ? View.VISIBLE : View.GONE);
            txtRequest3.setText(b.getPostageString());
            txtRequest.setText(b.getBrushRequirement());
            if (!TextUtils.isEmpty(b.getBrushWorkflowPic())) {
                Glide.with(this).load(b.getBrushWorkflowPic()).into(img_show);
            }
        }
    }

    DecimalFormat df = new DecimalFormat("###0.00");

    private String getSex(RequirementMapBean sex) {
        if (sex == null) {
            return "不限";
        }
        switch (sex.getSex()) {
            case 0:
                return "不限";
            case 1:
                return "男";
            case 2:
                return "女";
            default:
                return "不限";
        }
    }

    @Override
    public void onReceiver(Context context, Intent intent) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.btn_suborder, R.id.btn_suborder2})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_suborder:
                switch (b.getThridPlatform()) {//1.淘宝，2.天猫，3、京东
                    case 3:
                        UIUtils.goJd(ActivityThirdOrderDo.this, b.getThridPlatformId(), (b.getTaokoulingStr() == null || TextUtils.isEmpty(b.getTaokoulingStr())) ? (b.getTaskGoods() == null ? "" : b.getTaskGoods().getGoodsTitle()) : b.getTaokoulingStr());
                        break;
                    case 1:
                        UIUtils.gotb(ActivityThirdOrderDo.this, b.getThridPlatformId(), (b.getTaokoulingStr() == null || TextUtils.isEmpty(b.getTaokoulingStr())) ? (b.getTaskGoods() == null ? "" : b.getTaskGoods().getGoodsTitle()) : b.getTaokoulingStr());
                        break;
                    case 2:
                        UIUtils.gotm(ActivityThirdOrderDo.this, b.getThridPlatformId(), (b.getTaokoulingStr() == null || TextUtils.isEmpty(b.getTaokoulingStr())) ? (b.getTaskGoods() == null ? "" : b.getTaskGoods().getGoodsTitle()) : b.getTaokoulingStr());
                        break;
                }
                break;
            case R.id.btn_suborder2:
                Bundle bundle = new Bundle();
                bundle.putSerializable(Constants.KEY_ORDER_BEAN, b);
                IntentUtil.gotoActivity(ActivityThirdOrderDo.this, ActivitySetOrderInfo.class, bundle);
                break;
        }
    }
}
